package com.dahua.simplefactory.version3;

/**
 * @author sunhongguang
 * @create 2022-01-09-11:35
 */
public class Calculate {

    /**
     * 获取计算结果
     *
     * @param numberA 第一个参与运算的数字
     * @param numberB 第二个参与运算的数字
     * @param operate 操作符
     * @return 返回运算的结果
     */
    public static double GetResult(double numberA, double numberB, String operate) {
        Double result = null;
        switch (operate) {
            case "+":
                result = numberA + numberB;
                break;
            case "-":
                result = numberA - numberB;
                break;
            case "*":
                result = numberA * numberB;
                break;
            case "/":
                if (numberB != 0) {
                    result = numberA / numberB;
                } else {
                    throw new RuntimeException("除数不能为0");
                }
                break;
        }
        return result;
    }

}
